using UnityEngine;
using QFramework;
using UnityEngine.UI;
using System.Security.Cryptography;

namespace ProjectSurvivor
{
	public partial class FlotingTextController : ViewController
	{
		void Start()
		{
			// Code Here
			FlotingText.Hide();
		}
		public static void Play(Vector2 position, string text)
		{
			mDefault.FlotingText.InstantiateWithParent(mDefault.transform)
			.Position(position.x, position.y)
		   .Self(f =>
		   {
			   var positionY = position.y;
			   var textTrans = f.transform.Find("Text");
			   var textComp = textTrans.GetComponent<Text>();
			   textComp.text = text;


			   ActionKit.Sequence().Lerp(position.y, position.y + 0.5f, 0.5f, (p) =>
			  {
				  f.PositionY(positionY + p * 0.5f);
				  textComp.LocalScaleX(Mathf.Clamp01(p * 8));
				  textComp.LocalScaleY(Mathf.Clamp01(p * 8));
			  })
			  .Delay(0.5f)
			  .Lerp(1.0f, 0, 0.3f, (p) =>
			  {
				  textComp.ColorAlpha(p);
			  }, () => { textTrans.DestroyGameObjGracefully(); })
			  .Start(textComp);
		   }).Show();
		}
		private static FlotingTextController mDefault;
		void Awake()
		{
			mDefault = this;
		}
		void OnDestroy()
		{
			mDefault = null;
		}
	}
}
